package com.iplatform.auth.feign;

import com.iplatform.module.auth.AuthUserDetailsFacade;
import com.iplatform.module.privilege.PriManagerBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * 动态路由用户中心client
 * @author red
 */
@Component
public class UserCenterClient {

    @Autowired
    @LoadBalanced
    private RestTemplate restTemplate;

    private static final String GET_USER_BY_CODE_URL ="/api/v1/manager/";

    /**
     * 通过serviceId和userCode获取用户
     * 此调用方式下，对应微服务必须提供/api/v1/manager/{username}接口，以获取用户信息
     * 后期可改造此处
     * @param serviceId 用户中心服务名
     * @param userCode 用户账户
     */
    public ResponseEntity<AuthUserDetailsFacade> getManager(String serviceId,String userCode){
        return restTemplate
                .getForEntity("http://"+serviceId+GET_USER_BY_CODE_URL+userCode,
                        AuthUserDetailsFacade.class);
    }
}
